package com.atguigu.guli.service.oss.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.oss.config.OssProperties;
import com.atguigu.guli.service.oss.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * ClassName: FileController <br/>
 * Description: <br/>
 *
 * @author ZMR<br />
 * date: 2020/12/19 22:20<br/>
 * @since JDK 1.11
 */
@RestController
@Slf4j
@RequestMapping("/admin/oss/file")
@Api(tags = "文件管理模块")
public class FileController {
    @Autowired
    OssProperties ossProperties;
    @Autowired
    FileService fileService;

    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public R uploadFile(MultipartFile multipartFile, @ApiParam(value = "模块名，用来区分不同模块的云储存路径") @RequestParam String module) {
        String path = fileService.uploadFile(multipartFile, module);

        System.out.println(module);
        return R.ok().data("path", path);
    }
}
